package jms;



//import xml.ReaderXML;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;

import xml.ReaderXML;

import java.util.Properties;

public class SenderInicial {
  //public static void main(String[] args ) {
   public static void enviar(){

             QueueConnection qc = null;
             try {
                 Properties p = new Properties();
                 p.put(Context.INITIAL_CONTEXT_FACTORY, "org.mom4j.jndi.InitialCtxFactory");
                 p.put(Context.PROVIDER_URL, "xcp://localhost:8001");
                 Context ctx = new InitialContext(p);
                 QueueConnectionFactory qcf =
                     (QueueConnectionFactory)ctx.lookup("QueueConnectionFactory");
                 Queue queue = (Queue)ctx.lookup("testQueue");
                 qc = qcf.createQueueConnection("system", "system");
                 QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                 QueueSender qsend = qs.createSender(queue);
                 TextMessage tm = qs.createTextMessage();
                 tm.setText("M1 de TGR");
                 tm.setStringProperty("string", "test");
                 String docF4311Z1 = ReaderXML.readXMLM1();
                 System.out.println("xml enviado a la cola: "+docF4311Z1);
                 tm.setStringProperty("m1tgr",  docF4311Z1);                
                 qsend.send(tm);
                 qsend.close();
                 qs.close();
             } catch(Exception ex) {
                 ex.printStackTrace();
             } finally {
                try {
                    qc.close();
                } catch(Exception ex) {
                   System.out.println(ex.getMessage());

                }
             }
         }

}
